package cn.edu.niit.alienlab.jshttplessonserver.service;

import cn.edu.niit.alienlab.jshttplessonserver.dto.MovieInfo;
import cn.edu.niit.alienlab.jshttplessonserver.dto.UserInfo;
import cn.edu.niit.alienlab.jshttplessonserver.dto.WeiboItem;
import org.apache.catalina.User;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Lesson1DataTool {

    private static List<WeiboItem> weiboItemList=new ArrayList<WeiboItem>();

    /**
     * 初始化动态数据
     * @return 动态数据数组
     */
    public static List<WeiboItem> getWeiboItemList(){
        if(weiboItemList.size()==0){
            generateWeiboItemList();
        }
        return weiboItemList;
    }
    /**
     * 创建10个动态信息
     */
    public static void generateWeiboItemList(){
        generateMovieInfoList();
        generateUserInfoList();
        for (int i=0;i<10;i++){
            WeiboItem weiboItem=new WeiboItem();
            weiboItem.setUuid(UUID.randomUUID().toString());
            weiboItem.setItemText("发布了一条新影片动态");
            weiboItem.setItemTitle("新影片动态");
            weiboItem.setMovieInfo(movieInfoList.get(i));
            weiboItem.setUserInfo(userInfoList.get(i));
            weiboItem.setPublishTime(LocalDateTime.now().minusMinutes((i+1)*2));
            weiboItemList.add(weiboItem);
        }
    }

    private static List<MovieInfo> movieInfoList=new ArrayList<MovieInfo>();

    public static List<MovieInfo> getMovieInfoList() {
        return movieInfoList;
    }

    /**
     * 创建10个影片信息
     */
    public static void generateMovieInfoList(){
        String [] movieDataArray={
                "270513|冰刀里的夏日||http://img5.mtime.cn/mt/2021/06/17/195520.26460884_1280X720X2.jpg|0|4|2021|102",
                "270519|移居者|Settlers|http://img5.mtime.cn/mt/2021/06/18/100047.97856789_1280X720X2.jpg|0|5|2021|103",
                "270521|不在远方||http://img5.mtime.cn/mt/2021/06/19/091558.30096567_1280X720X2.jpg|0|7|2021|106",
                "270532|红船||http://img5.mtime.cn/mt/2021/07/08/165950.49243741_1280X720X2.jpg|0|13|2021|111",
                "270536|山歌|Folk Song|http://img5.mtime.cn/mt/2021/06/23/090201.71921695_1280X720X2.jpg|0|4|2021|96",
                "270547|爱的富硒泉||http://img5.mtime.cn/mt/2021/06/26/090043.20226594_1280X720X2.jpg|0|0|2021|90",
                "270548|再见汪先森||http://img5.mtime.cn/mt/2021/06/26/174338.22578478_1280X720X2.jpg|0|13|2021|98",
                "270555|雨和你的故事|Endless Rain|http://img5.mtime.cn/mt/2021/06/28/101555.73050840_1280X720X2.jpg|0|18|2021|117",
                "270561|⼀席.之地|GAIN A  FOOTHOLD|http://img5.mtime.cn/mt/2021/06/28/170934.68410332_1280X720X2.jpg|0|4|2021|97",
                "270563|青春不悔||http://img5.mtime.cn/mt/2021/06/29/085458.18716954_1280X720X2.jpg|0|1|2021|103"
        };
        for(int i=0;i<movieDataArray.length;i++){
            MovieInfo movieInfo=new MovieInfo(movieDataArray[i]);
            movieInfoList.add(movieInfo);
        }
    }

    private static List<UserInfo> userInfoList=new ArrayList<UserInfo>();
    public static List<UserInfo> getUserInfoList() {
        return userInfoList;
    }
    /**
     * 创建10个用户信息
     */
    public static void generateUserInfoList(){
        String [] iconImages={
                "http://img31.mtime.cn/ph/2016/08/08/113954.72833765_1280X720X2.jpg",
                "http://img5.mtime.cn/ph/2018/09/26/145842.65362465_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/2014/03/21/100813.45312129_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/1039/893039/893039_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/2014/02/22/193017.75925550_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/2014/12/28/091157.71486711_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/2014/08/06/135413.77084393_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/2014/03/21/084300.21206626_1280X720X2.jpg",
                "http://img5.mtime.cn/ph/2017/08/29/115210.63672629_1280X720X2.jpg",
                "http://img31.mtime.cn/ph/2014/10/19/102217.34424698_1280X720X2.jpg"
        };
        String [] userNames={
                "威尔·法瑞尔","崔·帕克","永井豪","金·波德尼亚","巴斯蒂安·帕斯特科瓦","爱德华·诺顿","查德·洛","吉姆·皮多克","黎明","李杨"
        };
        for(int i=0;i<10;i++){
            UserInfo user=new UserInfo();
            user.setUserId((long)i+1);
            user.setIconImage(iconImages[i]);
            user.setNickName(userNames[i]);
            userInfoList.add(user);
        }
    }
}
